package com.example.common.res;


import com.github.pagehelper.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * 分页结构
 * */
@Data
public class PageBean<T> implements Serializable {
    private long total;
    private List<T> list;
    private int pageNum;
    private int pageSize;
    private int pages;


    public PageBean(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.total = page.getTotal();
            this.pages = page.getPages();
            this.list = page;
        }
    }

    public PageBean() {
        this.total = 0L;
        this.list = new LinkedList<>();
        this.pages = 0;
        this.pageNum = 0;
        this.pageSize = 0;

    }


}
